package com.apes.fn.server.workDesk.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.ApesConst;
import com.apes.scm.rbac.model.User;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;
import org.squirrelframework.foundation.fsm.HistoryType;
import org.squirrelframework.foundation.fsm.StateCompositeType;

import javax.persistence.*;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = WorkDeskAssistantConfig.CONST_TABLE_NAME)
public class WorkDeskAssistantConfig extends Model {
    public static final String CONST_TABLE_NAME = "WORK_DESK_ASSISTANT_CONFIG";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "编码", padding = 12)
    private String id;

    @Column(name = "parent_id", length = 64)
    @Comment("上级")
    private String parentId;

    @Column(name = "name", length = 64)
    @Comment("名称")
    private String name;

    @Column(name = "form_id", length = 64)
    @Comment("页面")
    private String formId;  // 跳转页面或弹框页面的formId

    @Comment("单位")
    @Column(name = "unit_name")
    private String unitName;

    @States(name = "按钮状态", values = {
            @State(id = "link", name = "跳转页面"),
            @State(id = "drawer", name = "弹框显示")})
    @Column(name = "action", length = 64)
    @Comment("按钮状态")
    private String action;

    @Column(name = "sort", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("排序")
    private double sort = 0;

    @Column(name = "condition_model", length = 500)
    @Comment("条件")
    private String conditionModel;  // 弹框或跳转页面条件,使用JSON字符串格式，"DATE":"CREATE_DATE"表示CREATE_DATE是查询页面的时间范围，需要sql中提供指定名称的时间

    @Column(name = "query_id", length = 128)
    @Comment("查询语句")
    private String queryId;     // 查询总数时的查询语句

    @Column(name = "query_param", length = 500)
    @Comment("查询条件")
    private String queryParam;  // 执行查询语句时需要的入参，使用JSON字符串格式

    @Column(name = "img", length = 128)
    @Comment("图片")
    private String img;

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效标记")
    private boolean valid = true; //有效

    @Column(name = "null_err", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("空异常")
    private boolean nullErr = false; //true:当查询数量为0时带异常文本

    @Column(name = "null_err_msg", length = 128)
    @Comment("异常")
    private String nullErrMsg;  // 当nullErr = true时，携带该msg给前端
}
